```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Netty线程模型深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', 'Noto Serif SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8fafc;
            color: #1e293b;
            line-height: 1.6;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .highlight-box {
            background: linear-gradient(to right, rgba(99, 102, 241, 0.1) 0%, rgba(99, 102, 241, 0) 100%);
            border-left: 4px solid #4f46e5;
        }
        .code-block {
            background-color: #1e293b;
            color: #f8fafc;
            font-family: 'Courier New', Courier, monospace;
        }
        .section-icon {
            color: #4f46e5;
            font-size: 1.5rem;
        }
        .first-letter::first-letter {
            float: left;
            font-size: 3.5rem;
            line-height: 1;
            margin-right: 0.5rem;
            margin-top: 0.2rem;
            color: #4f46e5;
            font-weight: 700;
        }
    </style>
</head>
<body class="antialiased">
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 px-4 sm:px-6 lg:px-8">
        <div class="max-w-7xl mx-auto">
            <div class="flex flex-col lg:flex-row items-center">
                <div class="lg:w-1/2 mb-10 lg:mb-0 lg:pr-10">
                    <h1 class="text-4xl md:text-5xl font-bold mb-6 leading-tight">Netty线程模型深度解析</h1>
                    <p class="text-xl mb-8 text-indigo-100">探索高性能网络框架的核心架构与设计理念</p>
                    <div class="flex flex-wrap gap-4">
                        <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm font-medium">高性能</span>
                        <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm font-medium">异步IO</span>
                        <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm font-medium">事件驱动</span>
                        <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm font-medium">零拷贝</span>
                    </div>
                </div>
                <div class="lg:w-1/2">
                    <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1723033409933-a5eb56b3-c1d6-42df-ac8c-3520f17d26f5.png" alt="Netty线程模型" class="rounded-lg shadow-2xl border-4 border-white border-opacity-20 w-full">
                </div>
            </div>
        </div>
    </div>

    <!-- Navigation Tabs -->
    <div class="bg-white shadow-sm sticky top-0 z-10">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="flex overflow-x-auto">
                <a href="#overview" class="px-6 py-4 font-medium text-indigo-600 border-b-2 border-indigo-600">概述</a>
                <a href="#thread-model" class="px-6 py-4 font-medium text-gray-500 hover:text-indigo-600">线程模型</a>
                <a href="#architecture" class="px-6 py-4 font-medium text-gray-500 hover:text-indigo-600">架构设计</a>
                <a href="#performance" class="px-6 py-4 font-medium text-gray-500 hover:text-indigo-600">高性能设计</a>
                <a href="#implementation" class="px-6 py-4 font-medium text-gray-500 hover:text-indigo-600">实现细节</a>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
        <!-- Overview Section -->
        <section id="overview" class="mb-20">
            <div class="flex items-center mb-8">
                <i class="fas fa-info-circle section-icon mr-3"></i>
                <h2 class="text-3xl font-bold text-gray-800">Netty概述</h2>
            </div>
            
            <div class="first-letter text-gray-700 mb-8">
                <p>在现代互联网应用中，高并发和低延迟是两个非常重要的指标。无论是大型网站、金融应用，还是实时通信系统，都需要处理海量的并发请求，并保证响应的及时性。这时候，网络框架就显得尤为重要。<strong class="text-indigo-600">Netty</strong> 作为一款高性能的网络应用框架，因其高效、灵活和可扩展性，已经成为了许多企业级应用的首选。在 Netty 中，线程模型是其核心架构之一，也是实现高性能网络通信的关键。</p>
            </div>

            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1723033324383-c3a3d12b-7ac6-4c6d-b8db-0c69aac67d3c.png" alt="Netty线程模型" class="w-full h-48 object-cover">
                    <div class="p-6">
                        <h3 class="text-xl font-semibold mb-3">Reactor模式设计</h3>
                        <p class="text-gray-600">Netty 的线程模型采用了一种基于 Reactor 模式的设计，通过非阻塞 I/O 和事件驱动机制来高效地处理网络 I/O 事件。</p>
                    </div>
                </div>
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1723033362394-761e0bce-1d4b-4722-a272-b6c21236cad0.png" alt="Netty定位" class="w-full h-48 object-cover">
                    <div class="p-6">
                        <h3 class="text-xl font-semibold mb-3">高性能网络框架</h3>
                        <p class="text-gray-600">Netty 是一个高性能的、异步事件驱动的网络应用框架，专为简化和优化复杂、高负载的网络应用开发而设计。</p>
                    </div>
                </div>
            </div>

            <div class="mb-12">
                <h3 class="text-2xl font-semibold mb-6 text-gray-800">Netty的定位与优势</h3>
                <div class="grid md:grid-cols-2 lg:grid-cols-3 gap-6">
                    <div class="bg-white p-6 rounded-lg shadow-sm hover:shadow-md transition-shadow">
                        <div class="w-12 h-12 bg-indigo-100 rounded-full flex items-center justify-center mb-4">
                            <i class="fas fa-bolt text-indigo-600 text-xl"></i>
                        </div>
                        <h4 class="font-semibold mb-2">高性能网络通信</h4>
                        <p class="text-gray-600">通过非阻塞I/O和事件驱动模型，极大提升了网络通信的吞吐量和响应速度。</p>
                    </div>
                    <div class="bg-white p-6 rounded-lg shadow-sm hover:shadow-md transition-shadow">
                        <div class="w-12 h-12 bg-indigo-100 rounded-full flex items-center justify-center mb-4">
                            <i class="fas fa-random text-indigo-600 text-xl"></i>
                        </div>
                        <h4 class="font-semibold mb-2">灵活的协议支持</h4>
                        <p class="text-gray-600">内置多种常用协议实现，同时支持自定义协议开发，满足特定业务需求。</p>
                    </div>
                    <div class="bg-white p-6 rounded-lg shadow-sm hover:shadow-md transition-shadow">
                        <div class="w-12 h-12 bg-indigo-100 rounded-full flex items-center justify-center mb-4">
                            <i class="fas fa-expand text-indigo-600 text-xl"></i>
                        </div>
                        <h4 class="font-semibold mb-2">高可扩展性</h4>
                        <p class="text-gray-600">模块化架构和清晰接口设计，使功能扩展和维护变得简单直观。</p>
                    </div>
                    <div class="bg-white p-6 rounded-lg shadow-sm hover:shadow-md transition-shadow">
                        <div class="w-12 h-12 bg-indigo-100 rounded-full flex items-center justify-center mb-4">
                            <i class="fas fa-server text-indigo-600 text-xl"></i>
                        </div>
                        <h4 class="font-semibold mb-2">多种应用场景</h4>
                        <p class="text-gray-600">从简单客户端/服务器通信到复杂分布式系统，Netty都能胜任。</p>
                    </div>
                    <div class="bg-white p-6 rounded-lg shadow-sm hover:shadow-md transition-shadow">
                        <div class="w-12 h-12 bg-indigo-100 rounded-full flex items-center justify-center mb-4">
                            <i class="fas fa-building text-indigo-600 text-xl"></i>
                        </div>
                        <h4 class="font-semibold mb-2">企业级稳定性</h4>
                        <p class="text-gray-600">历经大规模应用验证，为高负载、高可用场景提供可靠解决方案。</p>
                    </div>
                    <div class="bg-white p-6 rounded-lg shadow-sm hover:shadow-md transition-shadow">
                        <div class="w-12 h-12 bg-indigo-100 rounded-full flex items-center justify-center mb-4">
                            <i class="fas fa-balance-scale text-indigo-600 text-xl"></i>
                        </div>
                        <h4 class="font-semibold mb-2">框架比较优势</h4>
                        <p class="text-gray-600">相比Apache Mina、Vert.x等框架，Netty在性能、灵活性上更胜一筹。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Thread Model Section -->
        <section id="thread-model" class="mb-20">
            <div class="flex items-center mb-8">
                <i class="fas fa-project-diagram section-icon mr-3"></i>
                <h2 class="text-3xl font-bold text-gray-800">Netty的线程模型</h2>
            </div>

            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-12 card-hover">
                <div class="md:flex">
                    <div class="md:w-1/2 p-8">
                        <h3 class="text-2xl font-semibold mb-4">线程模型核心组件</h3>
                        <p class="text-gray-700 mb-6">Netty 的线程模型主要由三个核心组件构成：<strong class="text-indigo-600">Boss 线程</strong>、<strong class="text-indigo-600">Worker 线程</strong>、以及 <strong class="text-indigo-600">EventLoopGroup</strong>。这些组件相互协作来处理网络事件。</p>
                        
                        <ul class="space-y-4">
                            <li class="flex items-start">
                                <span class="bg-indigo-100 text-indigo-800 rounded-full w-6 h-6 flex items-center justify-center mr-3 flex-shrink-0">1</span>
                                <span><strong>Boss 线程</strong>：负责监听连接请求并将其分配给 Worker 线程进行处理。通常只有一个或少量的 Boss 线程。</span>
                            </li>
                            <li class="flex items-start">
                                <span class="bg-indigo-100 text-indigo-800 rounded-full w-6 h-6 flex items-center justify-center mr-3 flex-shrink-0">2</span>
                                <span><strong>Worker 线程</strong>：负责处理 I/O 事件，执行读写操作和编解码。通常使用多个线程以提高并发处理能力。</span>
                            </li>
                            <li class="flex items-start">
                                <span class="bg-indigo-100 text-indigo-800 rounded-full w-6 h-6 flex items-center justify-center mr-3 flex-shrink-0">3</span>
                                <span><strong>EventLoopGroup</strong>：是一个线程池，包含多个 EventLoop 实例。每个 EventLoop 绑定一个线程，并负责一个或多个 Channel 的生命周期管理。</span>
                            </li>
                        </ul>
                    </div>
                    <div class="md:w-1/2 bg-gray-50 p-8 flex items-center justify-center">
                        <div class="mermaid w-full">
                            graph TD
                                A[Client] -->|Connection| B(BossGroup)
                                B -->|Register| C(WorkerGroup)
                                C --> D[EventLoop1]
                                C --> E[EventLoop2]
                                C --> F[EventLoop3]
                                D --> G[Channel1]
                                D --> H[Channel2]
                                E --> I[Channel3]
                                F --> J[Channel4]
                        </div>
                    </div>
                </div>
            </div>

            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div>
                    <h3 class="text-2xl font-semibold mb-4 text-gray-800">非阻塞 I/O (NIO)</h3>
                    <div class="highlight-box p-6 rounded-lg mb-6">
                        <p class="text-gray-700"><strong>非阻塞 I/O</strong>：Netty 使用 Java NIO 的 Selector 机制，可以在单个线程中管理多个 Channel。这种非阻塞模式允许一个线程在不阻塞的情况下处理多个 I/O 事件，大大提高了资源利用率。</p>
                    </div>
                    <div class="highlight-box p-6 rounded-lg">
                        <p class="text-gray-700"><strong>事件驱动</strong>：通过注册不同类型的事件（如连接、读、写等），Netty 可以在事件发生时触发相应的回调函数，避免了线程的频繁切换和阻塞等待。</p>
                    </div>
                </div>
                <div>
                    <h3 class="text-2xl font-semibold mb-4 text-gray-800">单线程处理原则</h3>
                    <div class="bg-white p-6 rounded-lg shadow-sm mb-6">
                        <p class="text-gray-700"><strong>单线程原则</strong>：每个 Channel 与一个 EventLoop 绑定，而 EventLoop 由单个线程执行。这种设计避免了多线程竞争和复杂的同步问题，提高了系统的吞吐量。</p>
                    </div>
                    <div class="bg-white p-6 rounded-lg shadow-sm">
                        <p class="text-gray-700"><strong>无锁化设计</strong>：通过细粒度的线程分配和单线程执行策略，Netty 减少了锁的使用，从而减少了上下文切换的开销。</p>
                    </div>
                </div>
            </div>

            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-12 card-hover">
                <div class="p-8">
                    <h3 class="text-2xl font-semibold mb-6 text-gray-800">线程模型工作流程</h3>
                    <div class="grid md:grid-cols-4 gap-6">
                        <div class="text-center">
                            <div class="bg-indigo-100 w-16 h-16 rounded-full flex items-center justify-center mx-auto mb-4">
                                <i class="fas fa-play text-indigo-600 text-2xl"></i>
                            </div>
                            <h4 class="font-semibold mb-2">初始化阶段</h4>
                            <p class="text-gray-600 text-sm">创建EventLoopGroup，注册ServerSocketChannel</p>
                        </div>
                        <div class="text-center">
                            <div class="bg-indigo-100 w-16 h-16 rounded-full flex items-center justify-center mx-auto mb-4">
                                <i class="fas fa-plug text-indigo-600 text-2xl"></i>
                            </div>
                            <h4 class="font-semibold mb-2">连接阶段</h4>
                            <p class="text-gray-600 text-sm">接受新连接并分配给Worker线程</p>
                        </div>
                        <div class="text-center">
                            <div class="bg-indigo-100 w-16 h-16 rounded-full flex items-center justify-center mx-auto mb-4">
                                <i class="fas fa-tasks text-indigo-600 text-2xl"></i>
                            </div>
                            <h4 class="font-semibold mb-2">事件处理阶段</h4>
                            <p class="text-gray-600 text-sm">处理读写事件和任务调度</p>
                        </div>
                        <div class="text-center">
                            <div class="bg-indigo-100 w-16 h-16 rounded-full flex items-center justify-center mx-auto mb-4">
                                <i class="fas fa-power-off text-indigo-600 text-2xl"></i>
                            </div>
                            <h4 class="font-semibold mb-2">关闭阶段</h4>
                            <p class="text-gray-600 text-sm">释放资源和线程回收</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Architecture Section -->
        <section id="architecture" class="mb-20">
            <div class="flex items-center mb-8">
                <i class="fas fa-sitemap section-icon mr-3"></i>
                <h2 class="text-3xl font-bold text-gray-800">Netty的多线程架构</h2>
            </div>

            <div class="mb-12">
                <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8 card-hover">
                    <div class="p-8">
                        <h3 class="text-2xl font-semibold mb-4">核心组件</h3>
                        <div class="grid md:grid-cols-3 gap-6">
                            <div>
                                <h4 class="font-semibold mb-3 text-indigo-600">EventLoop</h4>
                                <p class="text-gray-700">负责处理IO操作和事件的调度。一个EventLoop在它的生命周期内只绑定到一个线程上。</p>
                                <ul class="mt-3 space-y-2 text-sm text-gray-600">
                                    <li class="flex items-start">
                                        <i class="fas fa-circle text-xs mt-1 mr-2 text-indigo-500"></i>
                                        <span>单线程事件循环</span>
                                    </li>
                                    <li class="flex items-start">
                                        <i class="fas fa-circle text-xs mt-1 mr-2 text-indigo-500"></i>
                                        <span>维护任务队列</span>
                                    </li>
                                </ul>
                            </div>
                            <div>
                                <h4 class="font-semibold mb-3 text-indigo-600">EventLoopGroup</h4>
                                <p class="text-gray-700">EventLoop的集合，用于管理和分配多个EventLoop。</p>
                                <ul class="mt-3 space-y-2 text-sm text-gray-600">
                                    <li class="flex items-start">
                                        <i class="fas fa-circle text-xs mt-1 mr-2 text-indigo-500"></i>
                                        <span>BossGroup处理连接请求</span>
                                    </li>
                                    <li class="flex items-start">
                                        <i class="fas fa-circle text-xs mt-1 mr-2 text-indigo-500"></i>
                                        <span>WorkerGroup处理IO操作</span>
                                    </li>
                                </ul>
                            </div>
                            <div>
                                <h4 class="font-semibold mb-3 text-indigo-600">Channel</h4>
                                <p class="text-gray-700">网络连接的抽象，每个Channel都绑定到一个EventLoop上。</p>
                                <ul class="mt-3 space-y-2 text-sm text-gray-600">
                                    <li class="flex items-start">
                                        <i class="fas fa-circle text-xs mt-1 mr-2 text-indigo-500"></i>
                                        <span>关联Pipeline处理链</span>
                                    </li>
                                    <li class="flex items-start">
                                        <i class="fas fa-circle text-xs mt-1 mr-2 text-indigo-500"></i>
                                        <span>Handler处理业务逻辑</span>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8 card-hover">
                    <div class="p-8">
                        <h3 class="text-2xl font-semibold mb-4">工作原理</h3>
                        <div class="grid md:grid-cols-2 gap-8">
                            <div>
                                <div class="flex items-start mb-6">
                                    <div class="bg-indigo-100 rounded-full w-10 h-10 flex items-center justify-center mr-4 flex-shrink-0">
                                        <span class="text-indigo-600 font-bold">1</span>
                                    </div>
                                    <div>
                                        <h4 class="font-semibold mb-2">连接处理</h4>
                                        <p class="text-gray-700">BossGroup中的一个EventLoop监听端口，接受新连接并注册到WorkerGroup。</p>
                                    </div>
                                </div>
                                <div class="flex items-start">
                                    <div class="bg-indigo-100 rounded-full w-10 h-10 flex items-center justify-center mr-4 flex-shrink-0">
                                        <span class="text-indigo-600 font-bold">2</span>
                                    </div>
                                    <div>
                                        <h4 class="font-semibold mb-2">IO事件处理</h4>
                                        <p class="text-gray-700">WorkerGroup中的EventLoop处理分配给它的Channel的IO事件，单线程保证线程安全。</p>
                                    </div>
                                </div>
                            </div>
                            <div>
                                <div class="flex items-start mb-6">
                                    <div class="bg-indigo-100 rounded-full w-10 h-10 flex items-center justify-center mr-4 flex-shrink-0">
                                        <span class="text-indigo-600 font-bold">3</span>
                                    </div>
                                    <div>
                                        <h4 class="font-semibold mb-2">任务处理</h4>
                                        <p class="text-gray-700">EventLoop处理定时任务和用户自定义任务，通过任务队列高效执行。</p>
                                    </div>
                                </div>
                                <div class="flex items-start">
                                    <div class="bg-indigo-100 rounded-full w-10 h-10 flex items-center justify-center mr-4 flex-shrink-0">
                                        <span class="text-indigo-600 font-bold">4</span>
                                    </div>
                                    <div>
                                        <h4 class="font-semibold mb-2">线程模型扩展</h4>
                                        <p class="text-gray-700">可根据需求调整线程数量，适应不同硬件和应用场景。</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div>
                <h3 class="text-2xl font-semibold mb-6 text-gray-800">高性能设计理念</h3>
                <div class="grid md:grid-cols-2 gap-6 mb-12">
                    <div class="bg-white p-6 rounded-lg shadow-sm">
                        <div class="flex items-center mb-4">
                            <div class="bg-indigo-100 rounded-full w-10 h-10 flex items-center justify-center mr-4">
                                <i class="fas fa-unlock text-indigo-600"></i>
                            </div>
                            <h4 class="font-semibold">无锁化设计</h4>
                        </div>
                        <p class="text-gray-700">每个Channel的IO操作都在单一线程上执行，Netty避免了传统多线程模型中常见的锁竞争问题，从而提高了性能。</p>
                    </div>
                    <div class="bg-white p-6 rounded-lg shadow-sm">
                        <div class="flex items-center mb-4">
                            <div class="bg-indigo-100 rounded-full w-10 h-10 flex items-center justify-center mr-4">
                                <i class="fas fa-copy text-indigo-600"></i>
                            </div>
                            <h4 class="font-semibold">零拷贝</h4>
                        </div>
                        <p class="text-gray-700">通过Direct Buffer和Composite Buffer等技术，实现了数据的零拷贝，减少了不必要的数据拷贝和内存消耗。</p>
                    </div>
                    <div class="bg-white p-6 rounded-lg shadow-sm">
                        <div class="flex items-center mb-4">
                            <div class="bg-indigo-100 rounded-full w-10 h-10 flex items-center justify-center mr-4">
                                <i class="fas fa-sync-alt text-indigo-600"></i>
                            </div>
                            <h4 class="font-semibold">异步非阻塞</h4>
                        </div>
                        <p class="text-gray-700">Netty采用异步非阻塞IO模型，使得IO操作不会阻塞线程，从而提高了系统的吞吐量。</p>
                    </div>
                    <div class="bg-white p-6 rounded-lg shadow-sm">
                        <div class="flex items-center mb-4">
                            <div class="bg-indigo-100 rounded-full w-10 h-10 flex items-center justify-center mr-4">
                                <i class="fas fa-bolt text-indigo-600"></i>
                            </div>
                            <h4 class="font-semibold">事件驱动</h4>
                        </div>
                        <p class="text-gray-700">通过事件驱动机制，Netty能够高效地响应网络事件，并根据不同事件类型调用相应的处理器进行处理。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Implementation Section -->
        <section id="implementation" class="mb-20">
            <div class="flex items-center mb-8">
                <i class="fas fa-code section-icon mr-3"></i>
                <h2 class="text-3xl font-bold text-gray-800">线程模型实现细节</h2>
            </div>

            <div class="mb-12">
                <h3 class="text-2xl font-semibold mb-6 text-gray-800">核心类实现</h3>
                <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8 card-hover">
                    <div class="p-8">
                        <div class="flex items-start mb-6">
                            <div class="bg-indigo-100 rounded-lg p-4 mr-6 flex-shrink-0">
                                <i class="fas fa-cubes text-indigo-600 text-2xl"></i>
                            </div>
                            <div>
                                <h4 class="text-xl font-semibold mb-3">NioEventLoopGroup</h4>
                                <p class="text-gray-700 mb-4">是Netty中的线程池，负责管理和分配多个NioEventLoop。每个NioEventLoopGroup内部维护一个线程池，默认情况下，线程数量为CPU核心数的两倍。</p>
                                <div class="code-block p-4 rounded-lg mb-4">
                                    <pre class="text-sm"><code>public class NioEventLoopGroup extends MultithreadEventLoopGroup {
    protected EventLoop newChild(Executor executor, Object... args) {
        return new NioEventLoop(this, executor, (SelectorProvider) args[0],
                              ((SelectStrategyFactory) args[1]).newSelectStrategy(),
                              (RejectedExecutionHandler) args[2]);
    }
}</code></pre>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8 card-hover">
                    <div class="p-8">
                        <div class="flex items-start">
                            <div class="bg-indigo-100 rounded-lg p-4 mr-6 flex-shrink-0">
                                <i class="fas fa-recycle text-indigo-600 text-2xl"></i>
                            </div>
                            <div>
                                <h4 class="text-xl font-semibold mb-3">NioEventLoop</h4>
                                <p class="text-gray-700 mb-4">是EventLoop的具体实现类，负责具体的事件循环。每个NioEventLoop关联一个Selector，用于监听网络事件。</p>
                                <div class="code-block p-4 rounded-lg">
                                    <pre class="text-sm"><code>public class NioEventLoop extends SingleThreadEventLoop {
    private final Selector selector;
    
    protected void run() {
        for (;;) {
            try {
                int selectedKeys = selector.select();
                processSelectedKeys();
            } catch (Exception e) {
                handleException(e);
            }
        }
    }
}</code></pre>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="mb-12">
                <h3 class="text-2xl font-semibold mb-6 text-gray-800">事件处理机制</h3>
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-8">
                        <div class="grid md:grid-cols-2 gap-8">
                            <div>
                                <h4 class="text-xl font-semibold mb-4">ChannelPipeline</h4>
                                <p class="text-gray-700 mb-4">是一个双向链表，包含一系列的ChannelHandler。每个ChannelHandler负责处理特定的事件或业务逻辑。</p>
                                <div class="code-block p-4 rounded-lg">
                                    <pre class="text-sm"><code>public class DefaultChannelPipeline implements ChannelPipeline {
    public ChannelPipeline addLast(ChannelHandler handler) {
        AbstractChannelHandlerContext newCtx = 
            new DefaultChannelHandlerContext(this, handler);
        // 将handler添加到链表
        ...
        return this;
    }
}</code></pre>
                                </div>
                            </div>
                            <div>
                                <h4 class="text-xl font-semibold mb-4">ChannelHandler</h4>
                                <p class="text-gray-700 mb-4">是事件处理器，负责处理具体的业务逻辑。包括ChannelInboundHandler和ChannelOutboundHandler。</p>
                                <div class="code-block p-4 rounded-lg">
                                    <pre class="text-sm"><code>public class SimpleChannelInboundHandler&lt;I&gt; 
    extends ChannelInboundHandlerAdapter {
    
    protected abstract void channelRead0(ChannelHandlerContext ctx, I msg);
}</code></pre>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Performance Section -->
        <section id="performance" class="mb-20">
            <div class="flex items-center mb-8">
                <i class="fas fa-tachometer-alt section-icon mr-3"></i>
                <h2 class="text-3xl font-bold text-gray-800">Netty高性能设计</h2>
            </div>

            <div class="mb-12">
                <h3 class="text-2xl font-semibold mb-6 text-gray-800">设计原则</h3>
                <div class="grid md:grid-cols-3 gap-6 mb-8">
                    <div class="bg-white p-6 rounded-lg shadow-sm">
                        <div class="flex items-center mb-4">
                            <div class="bg-indigo-100 rounded-full w-10 h-10 flex items-center justify-center mr-4">
                                <i class="fas fa-sync-alt text-indigo-600"></i>
                            </div>
                            <h4 class="font-semibold">异步非阻塞IO</h4>
                        </div>
                        <p class="text-gray-700">通过Java NIO实现，避免阻塞线程等待IO操作。</p>
                    </div>
                    <div class="bg-white p-6 rounded-lg shadow-sm">
                        <div class="flex items-center mb-4">
                            <div class="bg-indigo-100 rounded-full w-10 h-10 flex items-center justify-center mr-4">
                                <i class="fas fa-bolt text-indigo-600"></i>
                            </div>
                            <h4 class="font-semibold">事件驱动架构</h4>
                        </div>
                        <p class="text-gray-700">利用事件循环机制，减少不必要的线程切换。</p>
                    </div>
                    <div class="bg-white p-6 rounded-lg shadow-sm">
                        <div class="flex items-center mb-4">
                            <div class="bg-indigo-100 rounded-full w-10 h-10 flex items-center justify-center mr-4">
                                <i class="fas fa-copy text-indigo-600"></i>
                            </div>
                            <h4 class="font-semibold">零拷贝技术</h4>
                        </div>
                        <p class="text-gray-700">减少数据复制，提高IO效率。</p>
                    </div>
                    <div class="bg-white p-6 rounded-lg shadow-sm">
                        <div class="flex items-center mb-4">
                            <div class="bg-indigo-100 rounded-full w-10 h-10 flex items-center justify-center mr-4">
                                <i class="fas fa-memory text-indigo-600"></i>
                            </div>
                            <h4 class="font-semibold">高效内存管理</h4>
                        </div>
                        <p class="text-gray-700">使用PooledByteBufAllocator进行内存池管理，减少GC压力。</p>
                    </div>
                    <div class="bg-white p-6 rounded-lg shadow-sm">
                        <div class="flex items-center mb-4">
                            <div class="bg-indigo-100 rounded-full w-10 h-10 flex items-center justify-center mr-4">
                                <i class="fas fa-expand text-indigo-600"></i>
                            </div>
                            <h4 class="font-semibold">可扩展线程模型</h4>
                        </div>
                        <p class="text-gray-700">通过NioEventLoopGroup提供灵活的线程分配策略。</p>
                    </div>
                    <div class="bg-white p-6 rounded-lg shadow-sm">
                        <div class="flex items-center mb-4">
                            <div class="bg-indigo-100 rounded-full w-10 h-10 flex items-center justify-center mr-4">
                                <i class="fas fa-cogs text-indigo-600"></i>
                            </div>
                            <h4 class="font-semibold">高度可定制性</h4>
                        </div>
                        <p class="text-gray-700">通过Pipeline和Handler机制实现业务逻辑与网络处理逻辑的分离。</p>
                    </div>
                </div>
            </div>

            <div class="mb-12">
                <h3 class="text-2xl font-semibold mb-6 text-gray-800">零拷贝技术实现</h3>
                <div class="grid md:grid-cols-3 gap-6">
                    <div class="bg-white rounded-lg shadow-md overflow-hidden card-hover">
                        <div class="p-6">
                            <div class="bg-indigo-100 w-12 h-12 rounded-lg flex items-center justify-center mb-4">
                                <i class="fas fa-memory text-indigo-600 text-xl"></i>
                            </div>
                            <h4 class="font-semibold mb-3">Direct Buffer</h4>
                            <p class="text-gray-700">使用堆外内存，避免了Java堆和操作系统内核缓冲区之间的数据复制。</p>
                            <div class="code-block p-3 rounded-lg mt-4">
                                <pre class="text-xs"><code>ByteBuffer directBuffer = ByteBuffer.allocateDirect(1024);</code></pre>
                            </div>
                        </div>
                    </div>
                    <div class="bg-white rounded-lg shadow-md overflow-hidden card-hover">
                        <div class="p-6">
                            <div class="bg-indigo-100 w-12 h-12 rounded-lg flex items-center justify-center mb-4">
                                <i class="fas fa-file text-indigo-600 text-xl"></i>
                            </div>
                            <h4 class="font-semibold mb-3">FileRegion</h4>
                            <p class="text-gray-700">利用操作系统的sendfile()系统调用，直接将文件数据从磁盘传输到网络，绕过用户态。</p>
                            <div class="code-block p-3 rounded-lg mt-4">
                                <pre class="text-xs"><code>FileRegion fileRegion = new DefaultFileRegion(file, 0, file.length());
channel.writeAndFlush(fileRegion);</code></pre>
                            </div>
                        </div>
                    </div>
                    <div class="bg-white rounded-lg shadow-md overflow-hidden card-hover">
                        <div class="p-6">
                            <div class="bg-indigo-100 w-12 h-12 rounded-lg flex items-center justify-center mb-4">
                                <i class="fas fa-layer-group text-indigo-600 text-xl"></i>
                            </div>
                            <h4 class="font-semibold mb-3">Composite Buffer</h4>
                            <p class="text-gray-700">通过多个ByteBuf合并成一个视图，减少数据复制。</p>
                            <div class="code-block p-3 rounded-lg mt-4">
                                <pre class="text-xs"><code>CompositeByteBuf compositeBuf = Unpooled.compositeBuffer();
compositeBuf.addComponents(true, headerBuf, bodyBuf);</code></pre>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div>
                <h3 class="text-2xl font-semibold mb-6 text-gray-800">高效内存管理</h3>
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-8">
                        <div class="grid md:grid-cols-2 gap-8">
                            <div>
                                <h4 class="text-xl font-semibold mb-4">ByteBuf优势</h4>
                                <ul class="space-y-3 text-gray-700">
                                    <li class="flex items-start">
                                        <i class="fas fa-check-circle text-indigo-500 mr-2 mt-1"></i>
                                        <span>支持池化管理，通过PooledByteBufAllocator减少内存分配和释放的开销</span>
                                    </li>
                                    <li class="flex items-start">
                                        <i class="fas fa-check-circle text-indigo-500 mr-2 mt-1"></i>
                                        <span>可以根据需要动态扩展大小，避免内存不足</span>
                                    </li>
                                    <li class="flex items-start">
                                        <i class="fas fa-check-circle text-indigo-500 mr-2 mt-1"></i>
                                        <span>支持多个ByteBuf合并、切片等操作，实现零拷贝</span>
                                    </li>
                                </ul>
                                <div class="code-block p-4 rounded-lg mt-6">
                                    <pre class="text-sm"><code>ByteBufAllocator allocator = PooledByteBufAllocator.DEFAULT;
ByteBuf buf = allocator.buffer(256);
buf.writeBytes(data);</code></pre>
                                </div>
                            </div>
                            <div>
                                <h4 class="text-xl font-semibold mb-4">内存泄漏检测</h4>
                                <p class="text-gray-700 mb-4">Netty提供了内存泄漏检测机制，帮助开发者发现和解决内存泄漏问题。</p>
                                <div class="bg-yellow-50 border-l-4 border-yellow-400 p-4 mb-6">
                                    <div class="flex">
                                        <div class="flex-shrink-0">
                                            <i class="fas fa-exclamation-triangle text-yellow-500"></i>
                                        </div>
                                        <div class="ml-3">
                                            <p class="text-sm text-yellow-700">
                                                支持不同级别的检测，如SIMPLE、ADVANCED、PARANOID。
                                            </p>
                                        </div>
                                    </div>
                                </div>
                                <div class="code-block p-4 rounded-lg">
                                    <pre class="text-sm"><code>// 启用内存泄漏检测
ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.ADVANCED);</code></pre>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </div>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
        
        // 平滑滚动
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });

        // 导航栏高亮
        window.addEventListener('scroll', function() {
            const sections = document.querySelectorAll('section');
            const navLinks = document.querySelectorAll('.flex.overflow-x-auto a');
            
            let current = '';
            sections.forEach(section => {
                const sectionTop = section.offsetTop;
                const sectionHeight = section.clientHeight;
                if (pageYOffset >= (sectionTop - 100)) {
                    current = section.getAttribute('id');
                }
            });
            
            navLinks.forEach(link => {
                link.classList.remove('text-indigo-600', 'border-indigo-600');
                link.classList.add('text-gray-500', 'hover:text-indigo-600');
                if (link.getAttribute('href') === `#${current}`) {
                    link.classList.remove('text-gray-500', 'hover:text-indigo-600');
                    link.classList.add('text-indigo-600', 'border-indigo-600');
                }
            });
        });
    </script>
</body>
</html>
```